import Vue from "vue";

import FormField from "~/components/basic/FormField.vue";

import Panel from '~/components/layout/panel.vue';
import Navigation from '~/components/layout/navigation.vue';
import Bottom from '~/components/layout/bottom.vue';

// 注册组件
Vue.component("form-field", FormField);

Vue.component('panel', Panel);
Vue.component('bottom', Bottom);
Vue.component('navigation', Navigation);

// 数字过滤器
Vue.filter("number", {
  read: function (value, bits = 3) {
    if (value) {
      return (parseFloat(value) || 0).toFixed(bits);
    }

    return value;
  },
  write: function (value) {
    if (value) {
      return parseFloat(value || 0).toFixed(bits);
    }

    return value;
  }
});

// 整数过滤器
Vue.filter("int", {
  read: function (value) {
    if (value) {
      return parseFloat(value).toFixed(0) || 0;
    }

    return value;
  },
  write: function (value) {
    if (value) {
      return parseFloat(value).toFixed(0) || 0;
    }

    return value;
  }
});

Vue.filter("style", function (n) {
  if (n && (n.title || n.field)) {
    return 'width:' + ((n.title || n.field).length * 10) + 'px;';
  }

  return "";
});
